const path = require('path');
const webpack = require('webpack');

module.exports = {
  devtool: 'cheap-module-eval-source-map',
  entry: [
    path.resolve(__dirname, './src/index.js'), //指定入口文件，程序从这里开始编译,__dirname当前所在目录, ../表示上一级目录, ./同级目录
  ],
  output: {
    path: path.resolve(__dirname, './dist'), // 输出的路径
    filename: 'bundle.js'  // 打包后文件
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin()
  ],
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      }, {
        test: /\.css$/,
        use: [{
          loader: 'style-loader'
        }, {
          loader: 'css-loader'
        }],
      }, {
        test: /\.less$/,
        use: [{
          loader: 'style-loader',
        }, {
          loader: 'css-loader',
        }, {
          loader: 'less-loader',
          options: {
            sourceMap: true,
          },
        }],
      }, {
        test: /\.png$/,
        use: [
          {
            loader: 'url-loader',
          },
        ],
      }
    ]
  },
  resolve:{
    extensions:['.js','.jsx','.json']   //表示这几种文件的后缀名可以省略，按照从前到后的方式来进行补全
  }
}